package com.coder520.workflow.controller;

import com.coder520.user.entity.User;
import com.coder520.workflow.entity.ReAttend;
import com.coder520.workflow.service.ReAttendService;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017-7-14.
 */
@Controller
@RequestMapping("reAttend")
public class ReAttendController {

    @Autowired
    private ReAttendService reAttendService;

    @RequestMapping
    public String reAttend(Model model, HttpSession session) {
        User user = (User) session.getAttribute("userInfo");
        List<ReAttend> reAttendList = reAttendService.reAttendList(user.getUsername());
        model.addAttribute("reAttendList",reAttendList);
        return "reAttend";
    }


    @RequestMapping("/start")
    public void start(@RequestBody ReAttend reAttend,HttpSession session) {//Map variables
//        User user = (User) session.getAttribute("userInfo");
//        reAttend.setReAttendStarter(user.getUsername());
        reAttend.setReAttendStarter("laozhao");
        reAttendService.startAttendFlow(reAttend);

        //reAttendService.startAttendFlow(variables);
    }

    @RequestMapping("/list")
    @ResponseBody
    public String list(ModelMap modelMap,HttpSession session) {
        User user = (User) session.getAttribute("userInfo");
        //String userName = "laozhao123";
        //List<ReAttend> reAttendList = reAttendService.listTasks(userName);
        List<ReAttend> reAttendList = reAttendService.reAttendList(user.getUsername());
        modelMap.addAttribute("reAttendList",reAttendList);

        return "reAttend";
    }

    @RequestMapping("/approve")///approve/{taskId}
    public void approve(@RequestBody ReAttend reAttend) {  //@PathVariable String taskId
        reAttendService.approve(reAttend);
    }

}
